<%@ page language="java" import="com.baomidou.mybatisplus.extension.plugins.pagination.Page" pageEncoding="utf-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    Page page1 = (Page) session.getAttribute("page");
    Long pages = (Long) session.getAttribute("pages");
    Integer currentPage = 1;
    boolean head = false;
    boolean tail = false;
    if (page1 != null) {
        if (page1.getCurrent() == 1) {
            head = true;
        }
        if (page1.getCurrent() == pages) {
            tail = true;
        }
    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>新闻中国</title>
    <link href="../../static/css/main.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../static/js/jquery-1.12.4.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="../../static/js/layer.js"></script>
    <script type="text/javascript" src="../../static/js/index.js"></script>
</head>
<body>

<div id="header">
    <div id="top_login">
        <div id="beforelogin">
            <label> 登录名 </label>
            <input type="text" id="adminname" value="admin" class="login_input"/>
            <label> 密&#160;&#160;码 </label>
            <input type="password" id="adminpwd" value="admin" class="login_input"/>
            <input type="button" class="login_sub" value="登录" onclick="login()"/>
            <input type="button" class="login_sub" value="注册" onclick="toRegister()"/>
        </div>

        <div id="loginok" style="display: none">
            欢迎：<input id="username" value="" style="border-style: none" readonly></input>
            <input onclick="loginOut()" type="button" value="退出登陆"/>
        </div>
        <img src="../../static/images/friend_logo.gif" alt="Google" id="friend_logo"/>
    </div>
    <div id="nav">
        <div id="logo"><img src="../../static/images/logo.jpg" alt="新闻中国"/></div>
        <div id="a_b01"></div>
    </div>
</div>
<div id="container">

    <div class="sidebar">
        <!-- 容纳左侧最新消息的容器 -->
        <%@ include file="./index-elements/index_sidebar.jsp" %>
    </div>
    <div class="class_type"><img src="../../static/images/class_type.gif" alt="新闻中心"/></div>
    <div id="myindex" style="float: left;padding-left: 3px" class="main">

        <div style="max-width: 500px">
            <input id="mysearch" style="border-color: #333333;padding-left: 2px" placeholder="请输入需要搜索的内容"
                   type="text">
            <button type="submit" onclick="search()">搜索</button>
        </div>

        <div align="content" style="min-width: 500px;float: left">
            <ul class="class_date" style="max-width: 500px">
                <!-- 新闻主题链接区域 -->
                <li id='class_month'><a onclick="queryPageByTopic(0)"><b>全部</b></a></li>
                <c:forEach items="${sessionScope.topic}" var="item">
                    <li id='class_month'><a onclick="queryPageByTopic(${item.tid})"><b>${item.tname}</b></a></li>
                </c:forEach>
            </ul>
            <div id="newscontent">
            </div>
        </div>
        <%@ include file="./index-elements/index_rightbar.jsp" %>
    </div>
</div>
<%@ include file="./index-elements/index_bottom.jsp" %>
</body>
<script>
    if (window.sessionStorage.getItem("username") != null) {
        document.getElementById("beforelogin").style.display = "none";
        document.getElementById("loginok").style.display = "block";
        console.log(window.sessionStorage.getItem("username"))
        document.getElementById("username").value = window.sessionStorage.getItem("username")
    }
    var globalPageNum = window.sessionStorage.getItem("globalPageNum")
    if (globalPageNum == null) {
        globalPageNum = 1
    }
    var globalTid = window.sessionStorage.getItem("globalTid")
    if (globalTid == null) {
        globalTid = 0
    }
    var globalKey = window.sessionStorage.getItem("globalKey")
    if (globalKey != null) {
        let a = globalKey.toString()
        console.log(a)
        document.getElementById("mysearch").value = globalKey
        // $('#mysearch').attr("value",globalKey);
    }
    $(function () {
        $.ajax({
            url: "news/getAllNews",
            method: "GET",
            data: {
                "pageNum": globalPageNum,
                "tid": globalTid,
                "keywords": globalKey
            },
            dataType: "html",
            success: function (response) {
                document.getElementById("newscontent").innerHTML = response
                // 处理后端响应数据
                // console.log(response);
            }
        })
    })


</script>
</html>
